﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using VM.Common.DataUntil;
using VM.Common.Result;
using VM.Entity.EntityMap.Member;
using VM.Entity.EntityMap.Title;
using VM.Entity.EntityMap.Topic;
using VM.IBLL.Member;
using VM.IBLL.Token;
using VM.IBLL.Title;
using VM.WebCore.Jwt;
using VM.WebCore.SwaggerExtend;
using VM.Entity.EntityDto.TitleDto;
using VM.Wechat;

namespace VM.WebAPI.Controllers
{

    /// <summary>
    /// 文章相关控制类
    /// </summary>
    [Route("api/title")]
    [ApiController]
    public class TitleController : ControllerBase
    {
        private readonly ITitleBLL _ITitleBLL;
        private readonly IJWTService _IJWTService;
        private readonly IHttpContextAccessor _HttpContextAccessor;

         
        public TitleController(IJWTService iJWTService, ITitleBLL iTitleBLL, IHttpContextAccessor httpContextAccessor)
        {

            _ITitleBLL = iTitleBLL;
            _IJWTService = iJWTService;
            _HttpContextAccessor = httpContextAccessor;
        }

        /// <summary>
        /// 添加文章 PHONE  
        /// </summary>
        /// <param name="sys_title">文章信息</param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]//要求通过授权才行---只要能鉴权成功，都能通过]
        [Route("addTitle")]
        [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ApiVersions.V1))]
        public ApiResult addTopic(sys_titleParent obj)
        {
            return _ITitleBLL.addTitle(obj);
        }
         
        /// <summary>
        /// 获取文章列表，   PC+PHONE
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize]//要求通过授权才行---只要能鉴权成功，都能通过]
        [Route("getTitleList")]
        [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ApiVersions.V1))]
        public ApiDataResult<PagingData<titleListDto>> getMemberInfoByPhone(int ? typeId ,string? name="",int pageIndex = 1, int pageSize = 100)
        {
            ApiDataResult<PagingData<titleListDto>> Res = _ITitleBLL.getTitleList(typeId, name, pageSize, pageIndex);
            return Res;
        }  
        /// <summary>
        /// 获取文章详情，   PC+PHONE
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize]//要求通过授权才行---只要能鉴权成功，都能通过]
        [Route("getTitleById")]
        [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ApiVersions.V1))]
        public ApiDataResult<titleDetailDto> getTitleById(int id )
        {
            //校验验证码是否可用，如果可用，返回true
            ApiDataResult<titleDetailDto> res = _ITitleBLL.getTitleDetailById(id);
            return res;
       
        }
         
    }

}
